﻿// Copyright 2009 William P. Hickey Jr. and William U. Walker
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//     
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//  
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
using GMap.NET;
using GMap.NET.WindowsForms;

namespace CSReporter
{
    public class MapCircle : GMapMarker
    {
        public Pen pen;

        public MapCircle(PointLatLng p, Color color, int thickness, int width, int height) : base(p)
        {
            pen = new Pen(color, thickness);
            Size = new System.Drawing.Size(width, height);
        }

        public override void OnRender(Graphics g)
        {
            System.Drawing.Rectangle rectangle = new System.Drawing.Rectangle(LocalPosition.X - Size.Width / 2, LocalPosition.Y - Size.Height / 2, Size.Width, Size.Height);
            g.DrawEllipse(pen, rectangle);
        }
    }

    public class MapDot : GMapMarker
    {
        public Pen pen;
        private Brush brush;

        public MapDot(PointLatLng p, Color color, int width, int height) : base(p)
        {
            pen = new Pen(color, 1);
            brush = new SolidBrush(color);
            Size = new System.Drawing.Size(width, height);
        }

        public override void OnRender(Graphics g)
        {
            System.Drawing.Rectangle rectangle = new System.Drawing.Rectangle(LocalPosition.X - Size.Width / 2, LocalPosition.Y - Size.Height / 2, Size.Width, Size.Height);
            g.DrawEllipse(pen, rectangle);
            g.FillEllipse(brush, rectangle);
        }
    }

    public class MapIcon : GMapMarker
    {
        private Image image;
        private Pen pen;
        private string callSign;
        private string station;
        private CSReportMessage csReport;

        public string CallSign
        {
            get { return callSign; }
        }

        public string Station
        {
            get { return station; }
        }

        public CSReportMessage CSReport
        {
            get { return csReport; }
        }

        public MapIcon(string callSign, string station, PointLatLng p, Image image)
            : base(p)
        {
            pen = new Pen(Color.Transparent, 1);
            Size = new System.Drawing.Size(20, 20);
            this.callSign = callSign;
            this.station = station;
            this.csReport = null;
            this.image = image;
        }

        public MapIcon(CSReportMessage csReport, PointLatLng p, Image image) : base(p)
        {
            pen = new Pen(Color.Transparent, 1);
            Size = new System.Drawing.Size(20, 20);
            this.callSign = csReport.FromCall;
            this.station = csReport.Station;
            this.csReport = csReport;
            this.image = image;
        }

        public override void OnRender(Graphics g)
        {
            System.Drawing.Rectangle rectangle;

            if (csReport != null)
            {
                if (csReport.StatusCode.Contains("G"))
                {
                    rectangle = new System.Drawing.Rectangle(LocalPosition.X - 25 / 2, LocalPosition.Y - 25 / 2, 25, 25);
                    g.FillEllipse(new SolidBrush(Color.LimeGreen), rectangle);
                }
                if (csReport.StatusCode.Contains("Y"))
                {
                    rectangle = new System.Drawing.Rectangle(LocalPosition.X - 31 / 2, LocalPosition.Y - 31 / 2, 31, 31);
                    g.DrawEllipse(new Pen(Color.Gold, 5), rectangle);
                }
                if (csReport.StatusCode.Contains("R"))
                {
                    rectangle = new System.Drawing.Rectangle(LocalPosition.X - 41 / 2, LocalPosition.Y - 41 / 2, 41, 41);
                    g.DrawEllipse(new Pen(Color.Red, 5), rectangle);
                }
            }
            rectangle = new System.Drawing.Rectangle(LocalPosition.X - Size.Width / 2, LocalPosition.Y - (Size.Height / 2) - 9, Size.Width, Size.Height);
            g.DrawEllipse(pen, rectangle);
            g.DrawImage(image, LocalPosition.X - 9, LocalPosition.Y - 9);
        }
    }
}
